#include <iostream>
#include <thread>
#include <mutex>
#include <vector>

using namespace std;

int counter = 0;
mutex mtx;

void add() {
    for (int i = 0; i < 10000; i++)
    {
        lock_guard<mutex> lock(mtx);
        ++counter;
    }
}

int main()
{
    const int THREAD_NUM = 4;
    vector<thread>threads;

    for (int i = 0; i < THREAD_NUM; i++)
    {
        threads.emplace_back(add);
    }
    for(auto& t : threads)
    {
        t.join();
    }

    cout << "Final counter: " << counter << endl;
    return 0;
}

